<template>
  <div class="main">
    <eagle-input
      class="input_text"
      label="应急演练人员"
      placeholder="请输入"
      v-model="form.DrillChnName"
      required
    >
    </eagle-input>
    <eagle-input
      class="input_text"
      label="应急演练地点"
      placeholder="请输入"
      v-model="form.DrillAddress"
      required
    >
    </eagle-input>
    <van-field
      class="input_text"
      label="应急演练资金"
      placeholder="请输入金额"
      required
      type="number"
      v-model="form.DrillMoney"
    >
    </van-field>
    <eagle-input
      class="input_text"
      label="应急演练单位名称"
      required
      v-model="form.DrillCompanyName"
      placeholder="请输入"
    >
    </eagle-input>
    <eagle-file-upload
      @CallBack="_fileUploadCb"
      :attachs="form.PlanAttachs"
      :labelName="'演练方案'"
      :mustInput="true"
      :cut="3"
    />
    <eagle-file-upload
      @CallBack="_fileUploadCbd"
      :attachs="form.DrillAttachs"
      :labelName="'演练记录'"
      :mustInput="true"
    />
    <eagle-file-upload
      @CallBack="_fileUploadCbs"
      :attachs="form.ScriptAttachs"
      :labelName="'演练脚本'"
      :maxCount="2"
      :isMulti="true"
      :mustInput="true"
    />
    <eagle-input
      class="input_text"
      label="备注"
      v-model="form.Remarks"
      type="textarea"
      autosize
      placeholder="请输入"
    >
    </eagle-input>
    <div class="bottom-buttons">
      <eagle-button
        square
        class="submit-button"
        type="primary"
        @click="_submit('0')"
        >提交</eagle-button
      >
      <eagle-button square class="save-btn" @click="_submit('1')" type="info"
        >暂存</eagle-button
      >
    </div>
  </div>
</template>

<script>

export default {
  data() {
    return {
      id: this.$route.query.id,
      form: {},
      filter: {
        id: this.$route.query.id,
      },
    };
  },
  created() {
    if (this.id > 0) {
      this.getDetail();
    }
  },
  methods: {
    _fileUploadCb(attachs) {
      this.form.PlanAttachs = attachs;
    },
    _fileUploadCbd(attachs) {
      this.form.DrillAttachs = attachs;
    },
    _fileUploadCbs(attachs) {
      this.form.ScriptAttachs = attachs;
    },
    getDetail() {
      let _this = this;
      _this.$axios
      .get("/PlanSimpleDrillPlan/GetDetail",{params:_this.filter})
      .then((res) => {
        _this.form = res.data;
      });
    },
    // 保存
    _submit(saveNum) {
      if (saveNum == "0") {
        this.form.DrillStatus = "100";
      } else if (saveNum == "1") {
        this.form.DrillStatus = "15";
      }

      if (!this.form.DrillChnName) {
        this.$toast("请输入应急演练人员");
        return;
      }
      if (!this.form.DrillAddress) {
        this.$toast("请输入应急演练地点");
        return;
      }
      if (!this.form.DrillMoney) {
        this.$toast("请输入应急演练资金");
        return;
      }
      if (!this.form.DrillCompanyName) {
        this.$toast("请输入应急演练单位名称");
        return;
      }
      if (!this.form.DrillAttachs) {
        this.$toast("请选择应急演练记录");
        return;
      }
      if (!this.form.PlanAttachs) {
        this.$toast("请选择应急演练方案");
        return;
      }
      if (!this.form.ScriptAttachs) {
        this.$toast("请选择应急演练脚本");
        return;
      }
      let _this = this;
      _this.$axios
      .post("/PlanSimpleDrillPlan/PostData",_this.form)
        .then((res) => {
          _this.$toast("保存成功");
          _this.loading = false;
          setTimeout(() => {
            _this.$router.goRefresh();
          }, 500);
        })
        .catch((err) => {
          console.log("err", err);
        });
    },
  },
};
</script>

<style lang="less">
.bottom-buttons {
  width: 100%;
  position: fixed;
  bottom: 0;
  left: 0;
  .submit-button {
    width: 50%;
    float: left;
    border: none;
    border-radius: 0;
  }
  .save-btn {
    width: 50%;
    float: left;
    border: none;
    border-radius: 0;
  }
}
</style>
